const express = require('express');
const axios = require('axios');
const app = express();
const cors = require('cors');
app.use(cors());
app.use(express.json());




const PORT = process.env.PORT || 8081;
const API_KEY = 'Link_iun3j1ESyXPzJXcEqeTIwMo41BWfNiMELvPL1X8ZxI'; // 请将 YOUR_API_KEY 替换为你的实际 API Key

app.post('/api/chat', async (req, res) => {
    try {
        const response = await axios.post('https://api.link-ai.tech/v1/chat/completions', {
            messages: req.body.messages
        }, {
            headers: {
                'Authorization': `Bearer ${API_KEY}`
            }
        });
        res.json(response.data);
    } catch (error) {
        console.error('Error calling LinkAI API:', error);
        res.status(500).send('Internal Server Error');
    }
});

app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});
